import { IDomEditor, IButtonMenu } from '@wangeditor/editor';

// 定义自定义菜单类
export class insertText implements IButtonMenu {
	title: string;
	tag: string;
	iconSvg?: string;
	alwaysEnable?: boolean;

	constructor() {
		this.title = "正文格式";
		this.tag = "button";
	}

	getValue(editor: IDomEditor): string | boolean {
		return "";
	}

	isActive(editor: IDomEditor): boolean {
		return false;
	}

	isDisabled(editor: IDomEditor): boolean {
		return false;
	}

	exec(editor: IDomEditor, value: string | boolean) {
		if (!editor.selection) return;

		// 1. 获取选中文本
		const selectedText = editor.getSelectionText();

		// 2. 创建要替换的HTML内容
		const newHtml = `<p 
			style="
				line-height: 2;
				font-weight: normal;
				text-align: justify;
			">
				<span style="
					font-size: 19px;
					text-align: justify;
				">
					${selectedText}
				</span>
			</p>`;

		// 3. 替换选中内容
		editor.dangerouslyInsertHtml(newHtml);
	}
}
